#!/usr/bin/env python
# examples of using the Multi-Valued Logic Toolkit by Koen Lefever 2009-2010, GPL v.3 licensed.

import MVL_Toolkit

# create some logics: Logic([list of truth values],[list of designated truth values])
# First some logics using Python's class inheritance mechanism
## Two-valued Logic
### classical proposition logic: False and True are Python's built-in booleans

pc = MVL_Toolkit.PC([False, True], [True])      # Check the file PC.py in the MVL_Toolkit to read the class definition.
pc.add_aliases(False, [0, '0', 'f', 'F', 'false', 'False', 'FALSE', 'off', 'Off', 'OFF', 'no', 'No', 'NO'])
pc.add_aliases(True, [1, '1', 't', 'T', 'true', 'True', 'TRUE', 'on', 'On', 'ON', 'yes', 'Yes', 'YES'])

## Three-valued Logics
### Lukasiewicz logic: 0 = false, 0.5 = unknown, 1 = true
class L3(MVL_Toolkit.Logic):
    def __init__(self):
        MVL_Toolkit.Logic.__init__(self, [0, 0.5, 1], [1])
    def AND(self, P, Q):
        return self.operator(113, P, Q)
    def OR(self, P, Q):
        return self.operator(4049, P, Q)
    def IF_THEN(self, P, Q):
        return self.operator(19418, P, Q)
    def NOT(self, P):
        return self.operator(19305, P, P)

l3 = L3()                               

### Kleene logic: F = false, U = undefined, T = true
class K3(MVL_Toolkit.Logic):
    def __init__(self):
        MVL_Toolkit.Logic.__init__(self, ['F', 'U', 'T'], ['T'])
    def AND(self, P, Q):
        return self.operator(113, P, Q)
    def OR(self, P, Q):
        return self.operator(4049, P, Q)
    def IF_THEN(self, P, Q):
        return self.operator(19337, P, Q)
    def NOT(self, P):
        return self.operator(19305, P, P)

k3 = K3()

### Jaskowski logic: F = false, P = paraconsistent state, T = true
class J3(MVL_Toolkit.Logic):
    def __init__(self):
        MVL_Toolkit.Logic.__init__(self, ['F', 'P', 'T'], ['P', 'T'])
    def AND(self, P, Q):
        return self.operator(113, P, Q)
    def OR(self, P, Q):
        return self.operator(4049, P, Q)
    def IF_THEN(self, P, Q):
        return self.operator(19094, P, Q)
    def NOT(self, P):
        return self.operator(19305, P, P)

j3 = J3()

# The next logic is created without using class inheritance
## Four-valued Logic
### paraconsistent logic used by Dunn/Belnap:
### {} = neither true nor false, {0} = false, {1} = true, {0,1} = both true and false
b4 = MVL_Toolkit.Logic(['{}', '{0}', '{1}', '{0,1}'], ['{1}', '{0,1}'])
b4.add_aliases('{0,1}',['{1,0}', '{0, 1}', '{1, 0}'])

def b4_INTERSECTION(P,Q):
    return b4.operator(1116699, P, Q)

#Uncomment the following lines to create b4_UNION operator & percentage Logic:
#def b4_UNION(P,Q):
#    return b4.operator(1116699, P, Q)

## 101-valued Logic
#percentage = MVL_Toolkit.Logic(range(0,101),range(50,101))
 

print "MVL examples have been loaded."
print
print "Please check the project website for instructions: "
print "  http://code.google.com/p/mvl-toolkit/wiki/ExamplesWiki"
print
